layui.define(['table', 'form', 'laypage', 'laydate', 'layer', 'carousel'], function (exports) {
    var $ = layui.$
        , table = layui.table
        , form = layui.form
        , laydate = layui.laydate
        , laypage = layui.laypage
        , layer = layui.layer
        , carousel = layui.carousel;

    //路径
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);

    $.ajax({
        type: "post",
        url: localhostPaht + projectName + "/rest/rfid/tableStructure?init=2",
        dataType: "json",
        async: false,
        success: function (data) {
            var aaa = {title: '操作', toolbar: '#operation', fixed: "right", align: 'center', width: 200};
            var ccc = {
                title: '状态',
                field: 'state',
                fixed: "right",
                align: 'center',
                width: 90,
                templet: '#state',
                sort: true
            };
            var bbb = {
                title: '出入状态',
                field: 'inOrOut',
                fixed: "right",
                align: 'center',
                width: 120,
                templet: '#inOrOut',
                sort: true
            };
            data.push(bbb)
            data.push(ccc)
            data.push(aaa)
            var limitcount = 10;
            table.render({
                elem: '#standingbook'
                , url: localhostPaht + projectName + "/rest/rfid/getMainTableSB?init=2"
                , toolbar: '#productLibraryTable'
                , height: 'full-255'
                , title: '物资台账'
                , cellMinWidth: 163
                , defaultToolbar: ['filter', 'print']
                , cols: [data]
                , page: false
                , limit: limitcount
                , text: {
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                // limits:[10, 20, 30, 40, 50],
                done: function (res, curr, count) {
                    $('.layui-table-fixed-r').removeClass('layui-hide');//列固定右侧
                    if (res.errorMsg == null) {

                    } else {
                        layer.msg(res.errorMsg);
                    }
                    var curnum = $("#curnum").val();
                    laypage.render({
                        elem: 'laypagetable'
                        , first: '首页'
                        , last: '尾页'
                        , groups: 5
                        , count: count
                        , curr: curnum
                        , limit: limitcount
                        , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                        , limits: [10, 15, 20]
                        , jump: function (obj, first) {
                            if (!first) {
                                curnum = obj.curr;
                                $("#curnum").val(curnum)
                                limitcount = obj.limit;
                                table.reload('standingbook', { //表格的id
                                    where: {
                                        page: curnum,
                                        limit: limitcount
                                    }
                                })

                            }
                        }
                    })
                    // table.exportFile(ins.config.id, res.data,'xls');
                }
            });

            //监听工具条
            table.on('tool(standingbooks)', function (obj) {  //表格的lay-filter="userlists"
                var data = obj.data; //获得当前行所有数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                if (obj.event === 'info') {
                    info(data)
                } else if (obj.event === 'standingbook') {
                    standingbook(data);
                }
            });
        }
    })

    function info(data) {
        layer.open({
            title: "详情",
            type: 2,
            content: localhostPaht + projectName + '/rest/getRoute?type=rfid&url=product_info',
            //是否显示右上角关闭图标，默认为1，显示
            area: ['90%', '91%'],
            maxmin: true,
            shade: 0.6,
            anim: 4,
            skin: 'layui-layer-molv',
            resize: true,
            success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                var iframe = window['layui-layer-iframe' + index];
                //调用子页面的全局函数
                iframe.child(data.id)
            }
        });
    }

    function standingbook(data){
        layer.open({
            title: "台账",
            type: 2,
            content: localhostPaht + projectName + '/rest/getRoute?type=rfid&url=standingbook_info',
            //是否显示右上角关闭图标，默认为1，显示
            area: ['90%', '91%'],
            maxmin: true,
            shade: 0.6,
            anim: 4,
            skin: 'layui-layer-molv',
            resize: true,
            success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                var iframe = window['layui-layer-iframe' + index];
                //调用子页面的全局函数
                iframe.child(data.id)
            }
        });
    }

    exports('standingbook', {})
});
